<template>
  <div class="container contract-review">
    <p class="bread">
      <a href="#/personalcenter">个人中心</a> >
      <a href="#/personalcenter/transac" class="font-s-18">订单管理</a> >
      <a href="javascript:void(0);" class="font-s-16">交易监控</a>
    </p>
    <div class="bg-c-fff box-border">
      <h3 class="tm-title">交易监控服务</h3>
      <step :stepData="stepData" :stepNum="stepNum" @stepRouter="stepRouter"></step>
    </div>
    <div class="content">
      <div class="box bg-c-fff box-border tc">
        <div class="file-box auto box-border">
          <ul>
            <li v-for="item in fileList" class="ico">
              <span class="iconfont icon-file-copy icon"></span>
              <a :href="item.address" download>{{item.address | fileName}}</a>
            </li>
          </ul>
        </div>
        <p class="tc state">状态：
          <span v-if="report === 0">待上传</span>
          <span v-else>已上传</span>
        </p>
        <div class="auto tc" v-show="showType">
          <input type="button" value="继续交易" class="blue-button" @click="showDetails()">
          <input type="button" value="终止交易" class="white-button" @click="showCanble()">
        </div>
      </div>
    </div>
    <vodal :show="msgShow" animation="zoom" :width="380" :height="230" @hide="msgShow = false">
      <div class="vodal-main vodal-tan-mes">
        <h4>提示</h4>
        <ul class="con">
          <li>您确认仔细查看资质报告后，确认后请选择下一步</li>
        </ul>
        <div class="tc auto vodal-btn-box">
          <button class="blue-button" @click="jump()">下一步</button>
        </div>
      </div>
    </vodal>
    <vodal :show="cbShow" animation="zoom" :width="380" :height="265" @hide="cbShow = false">
      <div class="vodal-main vodal-tan-mes">
        <h4>提示</h4>
        <ul class="con">
          <li>您确认终止交易，确认后请选择终止</li>
        </ul>
        <div class="tc auto vodal-btn-box">
          <button class="blue-button" @click="canble()">终止</button>
        </div>
      </div>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import UploaderManager from '../components/UploaderManager'
import Step from '../components/Step'
export default {
  components: {
    Step,
    UploaderManager
  },
  data() {
    return {
      stepNum: 1,
      stepData: [{
        name: '提交服务申请'
      }, {
        name: '确认资质报告'
      }, {
        name: '合同审查'
      }, {
        name: '绘制流程图'
      }, {
        name: '交易监控'
      }, {
        name: '服务评价'
      }],
      fileNum: '',
      report: 0,
      msgShow: false,
      cbShow: false,
      fileList: [],
      otherBusiness: '',
      seeShow: false,
      status: 0,
      stage: ''
    }
  },
  mounted() {
    this.getData()
    this.initUploader()
  },
  computed: {
    showType() {
      if (this.stage === 3) {
        return false
      } else if (this.status > 2) {
        return false
      } else {
        return true
      }
    }
  },
  methods: {
    stepRouter(i, name) {
      if (i === 0 && this.status >= 1) {
        this.$router.push('/submit-apply?id=' + this.$route.query.id)
      }
      if (i === 1 && this.status >= 2) {
        this.$router.push('/confirm-aptitude?id=' + this.$route.query.id)
      }
      if (i === 2 && this.status >= 3) {
        this.$router.push('/contract-review?id=' + this.$route.query.id)
      }
      if (i === 3 && this.status >= 4) {
        this.$router.push('/transac-service-wait?id=' + this.$route.query.id)
      }
      if (i === 4 && this.status >= 5) {
        this.$router.push('/transactionsurveillance?id=' + this.$route.query.id)
      }
      if (i === 5 && this.status >= 6) {
        this.$router.push('/service-evalua?id=' + this.$route.query.id)
      }
    },
    getData() {
      this.$http.post('/transactionMonitorSer/business/read/detail', {
        id: this.$route.query.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.otherBusiness = data.data.data.otherBusiness
          this.fileList = data.data.data.fileList
          this.report = data.data.data.reportNum
          this.status = data.data.data.status
          this.stage = data.data.data.stage
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    startUpload() {
      if (this.uploader.startUpload()) {

      } else {
        this.$toasted.show('正在上传文件，请稍后再试')
      }
    },
    initUploader() {
      this.uploader = new UploaderManager('content-photo', 'selectBtn', (url) => {
        this.newsPicImg = url
        this.$toasted.show('上传成功')
      })
    },
    see() {
      this.seeShow = true
    },
    showDetails() {
      if (this.report === 0) {
        this.$toasted.show('未上传资质报告,请等待')
        return
      }
      if (this.stage === 3) {
        this.$toasted.show('该订单已终止,若需求请发起新交易订单')
        this.$router.push('/personalcenter/transac')
        return
      }
      this.msgShow = true
    },
    showCanble() {
      this.cbShow = true
    },
    jump() {
      this.$http.post('/transactionMonitorSer/business/examineReport', {
        id: this.$route.query.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          if (data.data.data.businessNum === 0) {
            this.$router.push('/contract-review?id=' + this.$route.query.id)
          }
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络错误')
      })
    },
    canble() {
      this.$http.post('/transactionMonitorSer/business/tradingHalt', {
        id: this.$route.query.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$router.push('/personalcenter/transac')
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络错误')
      })
    }
  },
  filters: {
    fileName(v) {
      return v.split('/')[v.split('/').length - 1]
    }
  }
}

</script>
<style type="text/css" scoped>
.box-border {
  border: 1px solid #ddd;
}

.tm-title {
  line-height: 40px;
  padding-left: 35px;
  font-size: 14px;
  color: #282828;
  border-bottom: 1px solid #ddd;
}

.content {
  margin-bottom: 40px;
}

.content .box {
  margin-top: 20px;
  padding-bottom: 20px;
}

.white-button,
.blue-button {
  width: 245px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  margin: 25px 5px 45px 5px;
}

.file-box {
  min-height: 150px;
  line-height: 1;
  width: 600px;
  margin-top: 40px;
}


.state {
  line-height: 35px;
}

.ico {
  margin-top: 40px;
  line-height: 50px;
  margin-bottom: 50px;
  margin-left: 200px;
  text-align: left;
}

.icon {
  font-size: 50px;
  color: #d8e7ff;
  vertical-align: middle;
}

</style>
